<?php
//json处理
function json($code,$msg) {
	return json_encode(array('code' => $code, 'msg'=> $msg),JSON_UNESCAPED_UNICODE);
}
//后台登录
function adminlogin($use,$pwd)
{
	$data = DB::get_row("SELECT * FROM shop_config WHERE Id = 1");
	if ($data['pass'] == $pwd && $data['user'] == $use) {
		//登陆成功
		return die(json(1,'登陆成功！'));
	}else if ($data['user'] != $use) {
		return die(json(0,'账号错误！'));
	}else if ($data['pass'] != $pwd){
		return die(json(0,'密码错误！'));
	}else{
		return die(json(0,'登录失败！'));
	}
	DB::close();
}

//修改用户
function setuser($id,$use,$pwd,$money,$vip)
{
	if (DB::query("UPDATE app_user SET user='{$use}',pass='{$pwd}',`money`='{$money}',vip='{$vip}' WHERE Id='{$id}'")) {
		return die(json(1,'修改成功！'));
	}else{
		return die(json(0,'修改失败！'));
	}
}
//添加用户
function adduser($use,$pwd,$money,$vip)
{
	$time = date("Y/m/d");
	if (DB::query("INSERT INTO app_user (user, pass, `money`, vip, `time`)
VALUES ('{$use}', '{$pwd}', '{$money}', '{$vip}', '{$time}')")) {
		return die(json(1,'添加成功！'));
	}else{
		return die(json(0,'添加失败！'));
	}
}